package com.hanter.android.radlib.countdown;

import android.os.CountDownTimer;
import androidx.annotation.Nullable;

public class MyCountDownTimer extends CountDownTimer {

    public void setListener(@Nullable OnCountDownListener listener) {
        this.listener = listener;
    }

    public interface OnCountDownListener {
        void onTick(long millisUntilFinished);

        void onFinish();
    }

    @Nullable
    private OnCountDownListener listener;

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    public MyCountDownTimer(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (listener != null)
            listener.onTick(millisUntilFinished);
    }

    @Override
    public void onFinish() {
        if (listener != null)
            listener.onFinish();
    }

}
